<template>
  <div id="app">
    <el-container>
      <el-header>
        <div style="width: 100%;height: 100%;display: flex;align-items: center;justify-content: space-between">
          <div id="logo-container">
            <h3>LOGO</h3>
          </div>
          <login></login>
        </div>
      </el-header>
      <el-container>
        <el-aside id="menu-container" width="250">
          <xx-menu :menus="menus" :select="jumpTo" :default-active="defaultActive" :default-openeds="defaultOpeneds"></xx-menu>
        </el-aside>
        <el-main id="main-container">
          <div v-if="breadcrumbs.length>0" id="breadcrumb-container">
            <el-breadcrumb separator-class="el-icon-arrow-right" style="padding: 0 15px">
              <el-breadcrumb-item v-for="(menu, idx) in breadcrumbs" :key="idx">{{menu.name}}</el-breadcrumb-item>
            </el-breadcrumb>
          </div>
          <div class="router-view">
              <router-view></router-view>
          </div>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import Vue from 'vue'
import rs from './routes'
import xxmenu from '@/components/xx-menu.vue'
import login from '@/components/login.vue'
import Router from 'vue-router'

Vue.use(Router);
let routes = rs.routes();
let menus = rs.menus();
export default {
  name: 'app',
  router: new Router({
    routes: routes,
    mode: 'history',
  }),
  components:{
    "xx-menu": xxmenu,
    "login": login,
  },
  data() {
    return {
      menus: menus,
      admin:{},
    }
  },
  computed: {
    breadcrumbs: {
      get() {
        let os = [];
        let index = this.$route.fullPath;
        let loop = (menus) => {
          for(let menu of menus) {
            if (index.startsWith(menu.index)) {
              os.push(menu)
            }
            if(menu.subs&&menu.subs.length>0){
              loop(menu.subs)
            }
          }
        };
        loop(this.menus);
        return os
      }
    },
    defaultOpeneds: {
      get() {
        let os = [];
        let menus = this.breadcrumbs;
        for(let menu of menus) {
          os.push(menu.index)
        }
        return os
      }
    },
    defaultActive: {
      get() {
        return this.$route.fullPath
      }
    },
  },
  created() {
  },
  methods: {
    jumpTo(path) {
      // console.log(path)
    },
  }
}
</script>

<style>
  .el-aside {
    overflow-x: hidden;
    overflow-y: scroll;
    position: fixed;
    bottom: 0;
    top: 60px;
    background: #4c92b8;
    color: rgb(255, 208, 75);
  }
  .el-header {
    background: #4c92b8;
    color: rgb(255, 255, 255);
    position: fixed;
    height: 60px;
    left: 0;
    right: 0;
  }
  #logo-container{
    margin: 0 40px;
    cursor: pointer;
    color: rgb(75, 232, 170);
  }
  .el-header .el-dropdown-link {
    cursor: pointer;
    color: #ffffff;
  }
  #menu-container{
    width: 250px;
  }
  #menu-container .el-menu-item i, #menu-container .el-submenu__title i{
    color: #fff;
    margin-right: 5px;
  }
  #breadcrumb-container{
    padding: 15px 0;
    width: 100%;
    background: rgb(245, 244, 242);
    box-shadow: 0 1px 10px rgba(0, 0, 0, 0.22);
    border-radius: 5px;
  }
  #main-container {
    min-width: 1080px;
    position: fixed;
    left: 250px;
    top: 60px;
    right: 0;
    bottom: 0;
    overflow: auto;
    padding: 0;
  }
  .router-view {
    width: 96%;
    padding: 20px 2%;
  }
</style>
